package org.crumbleworks.crumbchat.server;

import org.crumbleworks.crumbchat.common.data.Message;
import org.crumbleworks.crumbchat.common.data.UserData;
import org.crumbleworks.crumbchat.server.controller.ServerControllerInterface;

import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;

public class ServerListener extends Listener.ReflectionListener {
    private ServerControllerInterface controller;

    public ServerListener(ServerControllerInterface controller) {
        this.controller = controller;
    }

    @Override
    public void connected(Connection connection) {

    }

    @Override
    public void disconnected(Connection connection) {
        connection.close();
    }

    public void received(Connection connection, UserData userData) {
        ChatConnection chatConnection = (ChatConnection) connection;
        chatConnection.setUserData(userData);
        
        System.out.println("bla");
    }
    
    public void received(Connection connection, Message message) {
        controller.putMessageToChat(message);
    }
}
